(function () {
    var io = ppt.io;

    function HomeScene() {
        HomeScene.super(this);

        this.ASSETS = {
            RES : ASSETS.PUBLIC,
            TYPE : "normal"
        };

        this.notify = null;
        this.menu = null;
        this.personalInfo = null;
        this.BG = null;
        this.role = null;
        
        this.init();
    }
    Laya.class(HomeScene, "Scene.Home", Laya.Sprite);
    var _proto = HomeScene.prototype;
    _proto.init = function () {
        this.size(GAME_CONFIG.WIDTH, Laya.stage.height);

        io.register({
            "role::role" : this.setRoleSkin,
            "pve::wait" : this.pvehome,
            "game::ready" : this.gameReady
        }, this);
    }
    _proto.pvehome = function (data) {
        var config = {
            msg : data.msg,
            close : true,
            btn : {
                btnCancel : false,
                btnConfirm : {
                    skin : "confirm"
                }
            }
        }
        switch(data.code){
            case 103://pve次数已用完
            case 116://pvp无法进入pve
                ppt.director.popScene(new Alert.Public(config));
                break;
        }
    }
    _proto.setRoleSkin = function (data) {
        this.role && this.role.destroy(true);
        
        var role = new Com.Home.Role(data.role);
            role.pos(GAME_CONFIG.WIDTH / 2 - 90, Laya.stage.height / 2 - 165);

        this.role = role;
        this.addChildAt(role, 1);
    }
    _proto.gameReady = function (data) {
        console.log("Home Scene to GameScene");
        ppt.director.runScene(new Scene.Game(data));
    }

    _proto.onAdd = function () {
        var BG = utils.createSkeleton("res/public/main");
            BG.play("hall", true);
            BG.pos(GAME_CONFIG.WIDTH / 2, Laya.stage.height / 2);

        var menu = new Com.Home.Menu();
            menu.centerX = 0;
            menu.bottom = -menu.height;
            menu.zOrder = 2;
        
        var notify = new Com.Home.Notify();
            notify.centerX = 0;
            notify.y = 100;

        this.BG = BG;
        this.menu = menu;
        this.notify = notify;
        this.addChildren(BG, menu, notify);

        io.emit({"cmd" : "role::role"});
    }
    _proto.onEnter = function () {
        this.notify.update();
        Laya.Tween.to(this.menu, {bottom : 0}, 300, Laya.Ease.circIn);
        ppt.header.enter("home");
    }
    _proto.onExit = function () {
        console.log("Home Scene Exited");
        io.unregister("role::role");
        io.unregister("game::ready", this.gameReady);
        io.unregister("pve::wait", this.pvehome);

        this.destroy(true);
        this.notify = null;
        this.menu = null;
        this.personalInfo = null;
        this.BG = null;
    }
    _proto.onResize = function (height) {
        this.height = height;

        this.BG.y = height / 2;
        this.menu.bottom = 0;

        this.role && (this.role.y = height / 2 - 165);
    }
})();